package com.yunlankeji.stemcells.activity.mine;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager2.widget.ViewPager2;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import com.google.android.material.tabs.TabLayoutMediator;

import android.content.Intent;
import android.os.Bundle;
import android.text.Layout;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

import com.google.android.material.tabs.TabLayout;
import com.yunlankeji.ganxibaozhijia.R;
import com.yunlankeji.stemcells.adapter.MyAdapter;
import com.yunlankeji.stemcells.adapter.ScreenSlidePagerAdapter;
import com.yunlankeji.stemcells.fragemt.fragment_mine_personal_space_fans;
import com.yunlankeji.stemcells.fragemt.fragment_mine_personal_space_follow;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;

public class mine_personal_space_followActivity extends AppCompatActivity {
    private TabLayout myTab;
    private ViewPager2 myPager2;
    private LinearLayout linearLayout;

    List<String> titles=new ArrayList<>();
    List<Fragment> fragments=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine_personal_space_follow);
        myTab=findViewById(R.id.tb_mine_personal_follow);
        myPager2=findViewById(R.id.vg_mine_personal_space_follow);
        linearLayout = findViewById(R.id.personal_space_search_lt);

        //添加标题
        titles.add("关注");
        titles.add("粉丝");

        //添加Fragment进去
        fragments.add(new fragment_mine_personal_space_follow());
        fragments.add(new fragment_mine_personal_space_fans());

        //实例化适配器
        MyAdapter myAdapter = new MyAdapter(getSupportFragmentManager(), getLifecycle(), fragments);
        //设置适配器
        myPager2.setAdapter(myAdapter);
        //TabLayout和Viewpager2进行关联
        new TabLayoutMediator(myTab, myPager2, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(titles.get(position));
            }
        }).attach();
        linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setClass(mine_personal_space_followActivity.this,Mine_personal_space_searchActivity.class);
                startActivity(intent);
            }
        });
    }
}